from PyQt5.QtCore import QThread, pyqtSignal
from model.yolov8_model import YOLONet

class DetectionThread(QThread):
    finished = pyqtSignal(object, int, dict)
    progress = pyqtSignal(int)

    def __init__(self, model_path, image_path, conf, iou):
        super().__init__()
        self.model = YOLONet()
        self.model.load_model(model_path)
        self.image_path = image_path
        self.model.conf_threshold = conf
        self.model.iou_threshold = iou

    def run(self):
        try:
            result = self.model.detect(self.image_path)
            self.finished.emit(*result)
        except Exception as e:
            self.finished.emit(None, 0, {"error": str(e)})